package br.com.tbp.main;

import br.com.tbp.gui.LoginDialog;
import javax.swing.ImageIcon;
import javax.swing.UIManager;

public class RunApp {

    private SplashScreen splashscreen;

    public RunApp() {
        // initialize the splash screen
        splashScreenInit();
        // do something here to simulate the program doing something that
        // is time consuming
        for (int i = 0; i <= 100; i++) {
            //for (long j = 0; j < 10; ++j) {
            for (long j = 0; j < 100000; ++j) {
                String poop = " " + (j + i);
            }
            if (i < 30) {
                splashscreen.setProgress("Conectando com o banco de dados " + i, i);
            } else if (i >= 30 && i < 90) {
                splashscreen.setProgress("Carregando interface gráfica " + i, i);
            } else {
                splashscreen.setProgress("Finalizado " + i, i);
            }
        }
        splashScreenDestruct();
    }

    private void splashScreenDestruct() {
        splashscreen.setScreenVisible(false);
        new LoginDialog(null, "TBP - Login", true).setVisible(true);
    }

    private void splashScreenInit() {
        ImageIcon myImage = new ImageIcon(
                RunApp.class.getResource("/br/com/tbp/resources/splash 0.3.PNG"));
        splashscreen = new SplashScreen(myImage);
        splashscreen.setLocationRelativeTo(null);
        splashscreen.setProgressMax(100);
        splashscreen.setScreenVisible(true);
    }

    public static void main(String[] args) {
        UIManager.put("swing.boldMetal", Boolean.FALSE);
        new RunApp();
    }
}
